package com.yang.guliproduct.controller;


import com.yang.guliproduct.entity.Category.OneCategory;
import com.yang.guliproduct.entity.PmsCategory;
import com.yang.guliproduct.service.impl.PmsCategoryServiceImpl;
import com.yang.guliproduct.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/guliproduct/pms-category")
//@CrossOrigin
public class PmsCategoryController {

    @Autowired
    private PmsCategoryServiceImpl pmsCategoryService;

    @GetMapping("getCategory")
    public R getCategory(){
        List<OneCategory> category = pmsCategoryService.getCategory();
        return R.ok().data("category",category);
    }

    @DeleteMapping("removeCategory/{id}")
    public R removeCategory(@PathVariable Long id){
        pmsCategoryService.removeById(id);
        pmsCategoryService.deleteCategoryBrand(id);
        return R.ok();
    }

    @PostMapping("insertCategory")
    public R insertCategory(@RequestBody PmsCategory pmsCategory){
        pmsCategoryService.save(pmsCategory);
        return R.ok();
    }
    @PostMapping("updateCategory")
    public R updateCategory(@RequestBody PmsCategory pmsCategory){
        pmsCategoryService.updateById(pmsCategory);
        pmsCategoryService.upCategoryBrand(pmsCategory);
        return R.ok();
    }



}

